import 'package:flutter/material.dart';
import 'package:keep_account_web/utils/call_back.dart';

import '../bean/day_work_record.dart';
import '../utils/screen_utils.dart';

class MonthlyWorkRecordsList extends StatelessWidget {

  final DeviceScreenType screenType;
  final List<DayWorkRecord> workRecords;
  final WorkRecordClickListener onLongClickListener;
  const MonthlyWorkRecordsList({super.key, required this.screenType, required this.workRecords, required this.onLongClickListener});


  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: workRecords.length,
        itemExtent: 118,
        shrinkWrap: true,
        physics: const BouncingScrollPhysics(),
        itemBuilder: (ctx,index){
          return workRecordsItemView(ctx,workRecords[index]);
        }
    );
  }

  Widget workRecordsItemView(BuildContext context,DayWorkRecord data) {
    return InkWell(
      onLongPress: (){
        onLongClickListener(data);
      },
      child: Card(
        elevation: 2,
        shadowColor: Theme.of(context).colorScheme.shadow,
        child: Container(
          padding: const EdgeInsets.all(10),
          decoration: BoxDecoration(
              color: Theme.of(context).colorScheme.onBackground,
              borderRadius: BorderRadius.circular(15)
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(data.workDate ?? "",style: const TextStyle(fontSize: 18,fontWeight: FontWeight.w500)),
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(todayTotalQuantity(data),style: const TextStyle(fontSize: 28,fontWeight: FontWeight.w600),),
                      const Text("产品数量",style: TextStyle(fontSize: 16),)
                    ],
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(todaySalary(data),style: const TextStyle(fontSize: 28,fontWeight: FontWeight.w600),),
                      const Text("当天工资",style: TextStyle(fontSize: 16),)
                    ],
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(todayTotalSingleQuantity(data),style: const TextStyle(fontSize: 28,fontWeight: FontWeight.w600),),
                      const Text("当日个人综合产量",style: TextStyle(fontSize: 16),)
                    ],
                  )
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

  String todayTotalQuantity(DayWorkRecord data){
    if ((data.teamSize ?? 0) > 0){
      if( (data.singleQuantity ?? 0) > 0 ){
        return "${(data.productQuantity ?? .0)}(${data.singleQuantity})";
      }else {
        return "${(data.productQuantity ?? .0)}";
      }
    }else{
      return "${data.singleQuantity}";
    }
  }

  String todaySalary(DayWorkRecord data){
    var teamSalary = (data.productQuantity ?? 0) * (data.productPrice ?? 0) / (data.teamSize ?? 0);
    var singleSalary = (data.singleQuantity ?? 0) * (data.productPrice ?? 0);
    if (teamSalary.isNaN){
      return "$singleSalary";
    }else if (singleSalary.isNaN){
      return "$teamSalary";
    }else {
      return "${teamSalary + singleSalary}";
    }

  }

  String todayTotalSingleQuantity(DayWorkRecord data){
    if ((data.teamSize ?? 0) > 0){
      if( (data.singleQuantity ?? 0) > 0 ){
        return "${(data.productQuantity ?? .0) /( data.teamSize ?? 0)}(${data.singleQuantity})";
      }else {
        return "${(data.productQuantity ?? .0) /( data.teamSize ?? 0)}";
      }
    }else{
      return "${data.singleQuantity}";
    }
  }


}